<?php

$plugin_info = array(
  'pi_name' => 'CrumbEE',
  'pi_version' => '1.0',
  'pi_author' => 'Iain Urquhart',
  'pi_author_url' => 'http://iain.co.nz/',
  'pi_description' => 'Returns a breadcrumb from current url',
  'pi_usage' => Crumbee::usage()
  );

class Crumbee
{
	var $return_data = "";

  	function Crumbee()
  	{
	  	global $TMPL;
	  	
	  	// Let see what's seperating the links
		$delimiter = $TMPL->fetch_param('delimiter');
		
	  	$crumblabel ="";
	  	
	  	// Grab the uri and chop it up, sanitize the REQUEST_URI
	    $parts = explode("/", htmlentities(dirname($_SERVER['REQUEST_URI']))); 
		foreach ($parts as $key => $dir) 
		{
        	switch ($dir) {
        	
        	/* Override labels from URLs if needed, to be nice */
        	case "about": $label = "About Us"; break;
        	case "index.php": $label = "Home"; break;
        	
        	/* if not, lets move along*/ 
        	default: $label = $dir; break;  

        }
        /* start fresh, then add each directory back to the URL */
        	$url = "";
        	for ($i = 1; $i <= $key; $i++) 
           	{ 
           		$url .= $parts[$i] . "/"; 
           	} 
           	// Build an exclude list
        	if ($dir != "index.php" && $dir != "entry" && $dir != "category" && $dir != "") 
        	{
        	$label = str_replace("-"," ",$label);
        	$crumblabel = str_replace("_"," ",$label); 
           	$this->return_data .= " <a href='/$url'>". ucwords($crumblabel) ."</a> ". $delimiter;
			}
		}
  }

  // ----------------------------------------
  //  Plugin Usage
  // ----------------------------------------

  function usage()
  {
  ob_start(); 
  ?>
	The Crumbee plugin creates a breadcrumb trail from the uri

	{exp:crumbee delimiter='>'}

	The delimiter='' parameter allows you to seperate breadcrumb links with whatever html element you want...

  <?php
  $buffer = ob_get_contents();
	
  ob_end_clean(); 

  return $buffer;
  }
  // END

}

?>